package com.cysyz.mylib.dao.sqloperaterrevolver.impl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cy on 2014/7/29.
 */
public class LikeOperatorRevolver extends BaseSqlOperatorRevolver {
    @Override
    public void addCond(StringBuilder sqlBuilder, List<Object> params, String column, String operator, Object value) {
        if (value != null && (value instanceof String)) {
            if (operator.equals("%like%")) {
                value = "%" + value + "%";
            } else if (operator.equals("like%")) {
                value = value + "%";
            } else if (operator.equals("%like")) {
                value = "%" + value;
            }
            operator = "like";
            super.addOneCond(sqlBuilder, params, column, operator, value);
        } else {
            throw new RuntimeException(">= operator just support String or number");
        }
    }


    @Override
    protected List<String> getSupportOperatorList() {
        List<String> supportList = new ArrayList<String>();
        supportList.add("%like%");
        supportList.add("like%");
        supportList.add("%like");
        return supportList;
    }


}
